package com.cloud.shopping.goods.controller;


import com.cloud.shopping.goods.model.Product;
import com.cloud.shopping.goods.service.SpuService;
import com.cloud.shopping.tool.RespResult;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author John.zhang
 * @since 2020-12-28
 */
@Api(tags = "商品SPU模块")
@RestController
@RequestMapping("/spu")
public class SpuController {

    @Resource
    private SpuService spuService;

    /**
     * 产品保存
     */
    @PostMapping(value = "/save")
    public RespResult save(@RequestBody Product product) {
        spuService.saveProduct(product);
        return RespResult.ok();
    }

    /**
     * 查询产品详情信息
     * @param id id
     * @return RespResult
     */
    @GetMapping(value = "/product/{id}")
    public RespResult<Product> one(@PathVariable(value = "id")String id){
        Product product = spuService.findBySupId(id);
        return RespResult.ok(product);
    }
}

